package io._520;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

public class StreamDemo {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        Random ran=new Random();
        for (int i = 0; i < 3; i++) {
            list.add(ran.nextInt(10));
        }
        System.out.println(list);
//        类似于包装类->Optional<Integer> min = list.stream().min((e1, e2) -> e1 - e2);
//        int n=min.get();
//        System.out.println(n);
        int min=list.stream().min((e1,e2)->e1-e2).get();
        System.out.println("最小值："+min);
        int max=list.stream().max((e1,e2)->e1-e2).get();
        System.out.println("最大值："+max);
        //判断集合中是否存在偶数？
        boolean anyMatch = list.stream().anyMatch(e -> e % 2 == 0);
        System.out.println("是否存在偶数:"+anyMatch);
        boolean allMatch = list.stream().allMatch(e -> e % 2 != 0);
        System.out.println("是否全部是鸡数:"+allMatch);
        boolean noneMatch = list.stream().noneMatch(e -> e <= 50);
        System.out.println("是否没有小于50的数:"+noneMatch);
//        Optional<Integer> reduce = list.stream().reduce((e1, e2) -> e1 + e2);
//        System.out.println("求和："+reduce.get());
        int d=list.stream().reduce((e1,e2)->e1+e2).get();
        System.out.println("求和："+d);

    }
}
